#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

void solve(){
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    sort(a.begin(), a.end());
    ll ans = a[0];
    if(k >= 3){
        cout << 0 << endl;
    }else if(k == 1){
        
        for(int i = 1; i < n; i++)
            ans = min(ans, a[i] - a[i -1]);
        cout << ans << endl;
    }else{
        for(int i = 0; i < n; i++){
            for(int j = i + 1; j < n; j++){
                ll d = a[j] - a[i];
                ans = min(ans, d);
                int p = lower_bound(a.begin(), a.end(), d) - a.begin();
                if(p + 1 < n) ans = min(ans, a[p + 1] - d);
                ans = min(ans, a[p] - d);
                if(ans == 0){
                    cout << 0 << endl;
                    return;
                }
            }
        }
        cout << ans << endl;
    }
}

int main(){
    int t;
    cin >> t;
    while(t--) solve();
    return 0;
}